/**
 * For the construction of Appolonian Gasket
 * A 3-uple of tangent circles
 */
package pluginUtils;

public class SoddyTriplet {
	private AGCircle a,b,c;
	// the two solutions for finding the forth tangent circle
	private AGCircle mini,maxi; 
	
	
	
	public SoddyTriplet(AGCircle a, AGCircle b, AGCircle c) {
		this.a = a;
		this.b = b;
		this.c = c;
		computeSolutions(); 
	} 
	
	
	
	public AGCircle getMini() {
		return mini;
	}


	public AGCircle getMaxi() {
		return maxi;
	}


	public AGCircle getA() {
		return a;
	}

	public AGCircle getB() {
		return b;
	}

	public AGCircle getC() {
		return c;
	}

	private void computeSolutions(){
		double k1=a.getCurvature(); 
		double k2=b.getCurvature(); 
		double k3=c.getCurvature();
		//int col=Math.abs(6-2*a.getColor()-3*b.getColor()-c.getColor())%5;
		int col=a.getColor(); 
		Complexe kz1=Complexe.mulbyDouble(a.getCenter(), k1); 
		Complexe kz2=Complexe.mulbyDouble(b.getCenter(), k2); 
		Complexe kz3=Complexe.mulbyDouble(c.getCenter(), k3); 
		double k4p=k1+k2+k3+2*Math.sqrt(k1*k2+k1*k3+k2*k3); 
		//System.out.println("k4p :"+ k4p);
		double k4m=k1+k2+k3-2*Math.sqrt(k1*k2+k1*k3+k2*k3);
		//System.out.println("k4m "+k4m);
		Complexe tempz4=Complexe.sum(Complexe.sum(kz1,kz2),kz3);
		Complexe temp=Complexe.sum(Complexe.sum(Complexe.mul(kz1,kz2),Complexe.mul(kz1,kz3)),Complexe.mul(kz2,kz3));
		temp=Complexe.mulbyDouble(Complexe.sqrt(temp),2); 
		Complexe kz4p=Complexe.sum(tempz4,temp);
		Complexe kz4m=Complexe.sub(tempz4, temp); 
		//System.out.println("kz4p/k4p : "+Complexe.mulbyDouble(kz4p,1/k4p)); 
		//System.out.println("kz4m/k4m : "+Complexe.mulbyDouble(kz4m,1/k4m) );
		
		if(k4p>k4m){ // k4p : max curvature, min radius
			mini=new AGCircle(Complexe.mulbyDouble(kz4p,1/k4p), Math.abs(1/k4p),false,col); 
			maxi=new AGCircle(Complexe.mulbyDouble(kz4m, 1/k4m), Math.abs(1/k4m),false,col); 
		}
		else{
			maxi=new AGCircle(Complexe.mulbyDouble(kz4p,1/k4p), Math.abs(1/k4p),false,col); 
			mini=new AGCircle(Complexe.mulbyDouble(kz4m,1/k4m), Math.abs(1/k4m)); 
		}
		
	}
	
	public static void main(String[] args) {
		double a=5,mu=3,c=2;
		AGCircle C0=new AGCircle(Complexe.createComplexeFromRI(0, c),mu+a,true); 
		AGCircle C1=new AGCircle(Complexe.createComplexeFromRI(0, -c),a-mu);
		AGCircle C2=new AGCircle(Complexe.createComplexeFromRI(0, a),mu+c); 
		SoddyTriplet test=new SoddyTriplet(C0, C1, C2); 
		System.out.println(test.mini); 
		System.out.println(test.maxi);
	}

}
